package de.hauck.rtmidlet.views;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;

import de.hauck.rtmidlet.RTMidlet;

public class CanvasInfo extends Canvas implements CommandListener {
	private String[][] _strings;
	private String _title;
	private Displayable _dble;
	private Font f_small,f_med;
	public CanvasInfo(Displayable dble, String title, String[][] strings) {
		_strings=strings;
		_dble=dble;
		_title = title;
		setFullScreenMode(true);
		setCommandListener(this);
		f_small = Font.getFont(Font.FONT_STATIC_TEXT, Font.STYLE_PLAIN,
				Font.SIZE_SMALL);
		f_med = Font.getFont(Font.FONT_STATIC_TEXT, Font.STYLE_PLAIN,
				Font.SIZE_MEDIUM);
	}
	
	protected void paint(Graphics g) {
		g.setColor(0);
		g.fillRect(0, 0, getWidth(), getHeight());
		g.setColor(255, 255, 255);
		int ypos=0;
		g.setFont(f_med);
		g.drawString(_title, getWidth()/2,
				0, Graphics.TOP | Graphics.HCENTER);
		g.setFont(f_small);
		ypos += f_small.getHeight() + 5;
		for (int i=0; i<_strings.length; i++) {
			g.drawString(_strings[i][0]+": ", 0,
					ypos, Graphics.TOP | Graphics.LEFT);
			g.drawString(_strings[i][1], getWidth(),
					ypos, Graphics.TOP | Graphics.RIGHT);
			ypos+=f_small.getHeight();
		}

	}
	
	public void setStrings(String [][] strings) {
		_strings=strings;
		repaint();
	}
	
	protected void keyPressed(int keyCode) {
		if (keyCode == -6 || keyCode == -7 || keyCode==KEY_STAR) {
			RTMidlet.getInstance().show(_dble);
		}
	}
	
	public void commandAction(Command command, Displayable dble) {
		// TODO Auto-generated method stub
		
	}

}